package org.dppc.fine4j.proxychain;

import java.lang.reflect.Method;

/**
 * 代理对象/方法的载体类（命令类）
 * 
 * @author maomh
 *
 */
public class MethodCommand {
	private Object proxy;
	private Object target;
	private Method method;
	private Object[] args = new Object[0];
	
	/**
	 * 构造方法
	 * 
	 * @param proxy
	 * @param target
	 * @param method
	 * @param args
	 */
	public MethodCommand(Object proxy, Object target, Method method, Object... args) {
		this.proxy = proxy;
		this.target = target;
		this.method = method;
		if (args != null && args.length > 0) {
			this.args = args;
		}
	}

	
	/**
	 * 直接执行代理方法
	 * 
	 * @return
	 * @throws Exception
	 */
	public Object execute() throws Exception {
		return method.invoke(target, args);
	}
	
	
	/**
	 * 获取代理对象<br/>
	 * 注意：这不是代理目标对象，若想获取代理目标对象请使用<code>getTarget()</code>
	 * 
	 * @return
	 */
	public Object getProxy() {
		return proxy;
	}

	public void setProxy(Object proxy) {
		this.proxy = proxy;
	}

	
	/**
	 * 获取代理目标对象
	 * 
	 * @return
	 */
	public Object getTarget() {
		return target;
	}

	public void setTarget(Object target) {
		this.target = target;
	}

	
	/**
	 * 获取代理方法
	 * 
	 * @return
	 */
	public Method getMethod() {
		return method;
	}

	
	public void setMethod(Method method) {
		this.method = method;
	}

	
	/**
	 * 获取代理方法的参数
	 * 
	 * @return
	 */
	public Object[] getArgs() {
		return args;
	}

	
	public void setArgs(Object[] args) {
		this.args = args;
	}

}
